var flag = true;   

$(function(){
	generateTable();
//	initGraphView();
});

//初始化图形显示
//function initGraphView(){
//	 var startTime = $("#StartTime").val();
//	 var endTime = $("#EndTime").val();
//
//	$.ajax({
//		type:'post',
//		async:false,
//		url:contextpath+'/logsystem/queryLogSystemGraphView.action',
//		dataType:'json',
//		data:{'startTime':startTime,
//			  'endTime':endTime},
//		success:getSucc,
//		error:getError
//	});
//}
//function getSucc(json){
// 	//接收后台传送过来的数据
// 	var line1 = new Array();
// 	var line2 = new Array();
// 	line1 = getDataByJson1(json);
// 	line2 = getDataByJson2(json);
// 	
// 	/***************************/
// 	$.jqplot('chartUser', [line1], {
// 	    title: '用户操作数量统计',
// 	    series:[{renderer:$.jqplot.BarRenderer}],
// 	    	axesDefaults: {
// 	    		tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
// 	            	tickOptions: {
// 	                     angle: -30,
// 	                     fontSize: '7pt'
// 	                   }
// 	               },
// 	               axes: {
// 	                 xaxis: {
// 	                   renderer: $.jqplot.CategoryAxisRenderer
// 	                 }
// 	               }
// 	             });
// 	             	             
// 	/**********************************/
// 	jQuery.jqplot ('chartOperation', [line2], 
// 	     { 
// 	     	title:"操作类型统计",
// 	     		seriesDefaults: {
// 	     			renderer: jQuery.jqplot.PieRenderer, 
// 	           	    	rendererOptions: {
// 	           	    		showDataLabels: true
// 	           	    	}
// 	           	 }, 
// 	           	legend: { show:true, location: 'e' }
// 	     }
// 	 );
//}

//function getDataByJson1(json){
// 	//接收后台传送过来的数据
// 	var arr2 = new Array();
// 	if(json.dataList1.length==0){
// 		arr2 = [["",0]];
// 	}else{
// 		for( var i=0;i<json.dataList1.length;i++){
// 		var map = json.dataList1[i];
// 		var arr1 = new Array();
// 		var times = map.times;
// 		var userName = map.userName;
// 		arr1[0] = userName;
// 		arr1[1] = times;
// 		arr2[i] = arr1;
// 	}
// 		}
// 	
// 	return arr2;
// }
 
// function getDataByJson2(json){
// 	//接收后台传送过来的数据
// 	var arr2 = new Array();
// 	if(json.dataList2.length==0){
// 		arr2 = [["",0]];
// 	}else{
// 		for( var i=0;i<json.dataList2.length;i++){
// 		var map = json.dataList2[i];
// 		var arr1 = new Array();
// 		var times = map.times;
// 		var operationType = map.operationType;
// 		arr1[0] = operationType;
// 		arr1[1] = times;
// 		arr2[i] = arr1;
// 	}
// 		}
// 	
// 	return arr2;
// }
 

function initQueryDropBox(){
	$.ajax({
		type:"get",
		url:contextPath+"/lottery/getDbaType.control",
		dataType:"json",
		success:getOperationSucc,
		error:getOperationError
	});
}

//为操作类型绑定下拉项
//function getOperationSucc(json){
//	var operationTypeDropBox = $("#OperationTypeDropBox");
//	for(var i=0;i<json.operationTypeList.length;i++){
//		var operationType = json.operationTypeList[i];
//		$("<option value = "+operationType+">"
//				+operationType+"</option>").appendTo(operationTypeDropBox);
//	}	
//}

//查询按钮
function QueryResult(){
	var StartTime =$("#StartTime").val();
	var EndTime =$("#EndTime").val();
	var OperationType = $("#OperationTypeDropBox").val();
	$("#dbgrid").jqGrid('setGridParam',{  
        datatype:'json',  
        postData:{'UserName':UserName,"StartTime":StartTime,"EndTime":EndTime}, //发送数据  
        page:1  
    }).trigger("reloadGrid"); //重新载入
	$("#chartUser").html("");
	$("#chartOperation").html("");
	initGraphView();
}

//function ExportResult(){
//	$.ajax({
//		type:'post',
//		url:contextPath+"/resource/test.action",
//		dataType:'json',
//		data:{"abc":'11',
//			"tom":'tom'},
//		success:getSucc,
//		error:getError
//	});	
//}
function generateTable(){
	var pageWidth = 1024;
//	alert("pageWidth db is:"+pageWidth);
	jQuery("#dbgrid").jqGrid({
		height: 250,
		autowidth:true,
//		hidden:true,
		url:contextpath+'/lottery/getAllDball.control',
		datatype:"json",
		colNames:['id',qihao,kjsj,first,second,third,fourth,fifth,sixth,blue],
		colModel:[
		          {name:"id",width:50,editable:true,key:true,align:"center"},
		          {name:"qihao",width:50,editable:true,align:"center"},
		          {name:"kjsj",width:(pageWidth*(8/100)*(80/100)),editable:true,align:"center"},
		          {name:"first",width:100,editable:true,align:"center"},
		          {name:"second",width:100,editable:true,align:"center"},
		          {name:"third",width:100,editable:true,align:"center"},
		          {name:"fourth",width:100,editable:true,align:"center"},
		          {name:"fifth",width:100,editable:true,align:"center"},
		          {name:"sixth",width:100,editable:true,align:"center"},
		          {name:"blue",width:100,editable:true,align:"center"}],
		            jsonReader : { 
		            page: "currentPageNo",   // json中代表当前页码的数据   
		     	   	total: "totalPageNum", // json中代表页码总数的数据   
		     	   	records: "totalRecords", // json中代表查询出的记录总数的数据   	
			   	    root: "dataList",   // json中代表实际模型数据的入口   
			   	    repeatitems: false// 如果设为false，则jqGrid在解析json时，会根据name来搜索对应的数据元素（即可以json中元素可以不按顺序）；而所使用的name是来自于colModel中的name设定。   
			   	} ,
			   	pager:"#pager",
			   	rowNum:10,
			   	rowList:[10,20,30],
			   	//lastpage:10,
			   	pgbuttons:true,
			   	pginput:true,
			    viewrecords: true,
			    recordtext: "View {0} - {1} of {2}",
			    emptyrecords: "No records to view",
			    loadtext: "Loading...",
				pgtext : "Page {0} of {1}",
				
			    rownumbers: true,
			    sortname: 'id',
			   	multiselect: true,
			   	caption:"双色球",
});
	
	
	jQuery("#dbgrid").jqGrid('navGrid','#pager',
			{
		edit:true,
		add:true,
		del:true,
		search:false,
		edittitle: "编辑彩票",
		addtitle: "添加彩票",
		deltitle: "删除彩票",
		refreshtitle:"刷新列表",
		edittext: "编辑",
		addtext: "添加",
		deltext: "删除",
		refreshtext:"刷新",
	    //delfunc:deleteRows
	}, //options
	
	{
		top:0,
		left:250,
		width:450,
		height:450,
		editCaption:"编辑彩票信息",
		recreateForm: true,
        //mtype: "PUT",
        jqModal: true,
        editCaption:"修改彩票",
		bSubmit: "修改",
		bCancel: "取消",
		url:contextPath+'/lottery/updateDball.control',
		processData: "处理中...",
		closeAfterEdit : true,
		reloadAfterSubmit:true
		  
	}, // edit options
	
	{
		top:0,
		left:250,
		width:450,
		height:450,
		addCaption:"添加彩票",
		recreateForm: true,
        //mtype: "PUT",
        jqModal: true,
        bSubmit: "添加", 
		bCancel: "取消",
		url:contextPath+'/lottery/addDball.control',
		processData: "处理中...",
		reloadAfterSubmit:true,
		closeAfterAdd:true
		
    }, // add options
    
	{
    	top:0,
		left:250,
		modal: false,
		msg: "删除选中行记录？",
		caption: "删除联系人",
		bSubmit: "确定", 
		bCancel: "取消",
		url:contextPath+'/lottery/deleteDball.control',
		reloadAfterSubmit:false}, // del options
	{} // search options
)


	}